package com.gitee.magic.jdbc.persistence.source.jdbc.criteria;

import java.util.ArrayList;
import java.util.List;

/**
 * @author start
 */
public abstract class BaseExample<T> {

	private boolean distinct;

	private List<T> oredCriteria;

	private String orderByClause;
	
	private Integer limitIndex;
	
	private Integer limitSize;

    public BaseExample() {
        this.oredCriteria = new ArrayList<>();
    }

    public void setOrderByClause(String orderByClause) {
        this.orderByClause = orderByClause;
    }


    public String getOrderByClause() {
        return orderByClause;
    }


    public void setLimitByClause(int index,int size) {
    	this.limitIndex=index;
    	this.limitSize=size;
	}
    
	public Integer getLimitIndex() {
		return limitIndex;
	}

	public Integer getLimitSize() {
		return limitSize;
	}

	public void setDistinct(boolean distinct) {
        this.distinct = distinct;
    }


    public boolean isDistinct() {
        return distinct;
    }


    public List<T> getOredCriteria() {
        return oredCriteria;
    }


    public void or(T criteria) {
        oredCriteria.add(criteria);
    }


    public T or() {
        T criteria = createCriteriaInternal();
        oredCriteria.add(criteria);
        return criteria;
    }


    public T createCriteria() {
        T criteria = createCriteriaInternal();
        if (oredCriteria.size() == 0) {
            oredCriteria.add(criteria);
        }
        return criteria;
    }

    /**
     * ignore
     * @return
     */
    protected abstract T createCriteriaInternal();
    
    /**
     * 清除分页所属条件
     */
    public void pageClear() {
        orderByClause = null;
        limitIndex=null;
        limitSize=null;
    }

    public void clear() {
        oredCriteria.clear();
        pageClear();
        distinct = false;
    }
	
}
